package com.rongshe.web.controller.hotel;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rongshe.common.annotation.Log;
import com.rongshe.common.core.controller.BaseController;
import com.rongshe.common.core.domain.AjaxResult;
import com.rongshe.common.enums.BusinessType;
import com.rongshe.hotel.domain.RsGoodUnit;
import com.rongshe.hotel.service.IRsGoodUnitService;
import com.rongshe.common.utils.poi.ExcelUtil;

/**
 * 商品规格Controller
 * 
 * @author rongshe
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/hotel/unit")
public class RsGoodUnitController extends BaseController
{
    @Autowired
    private IRsGoodUnitService rsGoodUnitService;

    /**
     * 查询商品规格列表
     */
    @GetMapping("/list")
    public AjaxResult list(RsGoodUnit rsGoodUnit)
    {
        List<RsGoodUnit> list = rsGoodUnitService.selectRsGoodUnitList(rsGoodUnit);
        return success(list);
    }

    /**
     * 导出商品规格列表
     */
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RsGoodUnit rsGoodUnit)
    {
        List<RsGoodUnit> list = rsGoodUnitService.selectRsGoodUnitList(rsGoodUnit);
        ExcelUtil<RsGoodUnit> util = new ExcelUtil<RsGoodUnit>(RsGoodUnit.class);
        util.exportExcel(response, list, "商品规格数据");
    }

    /**
     * 获取商品规格详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rsGoodUnitService.selectRsGoodUnitById(id));
    }

    /**
     * 新增商品规格
     */
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RsGoodUnit rsGoodUnit)
    {
        return toAjax(rsGoodUnitService.insertRsGoodUnit(rsGoodUnit));
    }

    /**
     * 修改商品规格
     */
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RsGoodUnit rsGoodUnit)
    {
        return toAjax(rsGoodUnitService.updateRsGoodUnit(rsGoodUnit));
    }

    /**
     * 删除商品规格
     */
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rsGoodUnitService.deleteRsGoodUnitByIds(ids));
    }
}
